﻿using Currency.Infra.EventBus.Cap;
using Autofac;
using System.Collections.Generic;
using System.Reflection;

namespace Currency.Infra.EventBus
{
    /// <summary>
    /// 注册事件总线
    /// </summary>
    public class AutofacEventBusModule : Autofac.Module
    {
        private readonly IEnumerable<Assembly> _assembliesToScan;

        public AutofacEventBusModule(IEnumerable<Assembly> assembliesToScan)
        {
            _assembliesToScan = assembliesToScan;
        }

        public AutofacEventBusModule(params Assembly[] assembliesToScan) : this((IEnumerable<Assembly>)assembliesToScan)
        {
        }

        /// <summary>
        /// Autofac注册
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            //注册事件发布者
            builder.RegisterType<CapPublisher>().As<IEventPublisher>().SingleInstance();
        }
    }
}